﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Xml.Linq;
using System.Collections.Generic;

using YouHP.BLL;
using YouHP.Model;

namespace web.admin
{
    public partial class Treatment : System.Web.UI.Page
    {
        private TreatmentBLL treatmentBll = TreatmentBLL.Instance;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ViewState["keyWordParm"] = "";

                bind(this.ViewState["keyWordParm"].ToString());
            }
        }

        protected void search_Click(object sender, EventArgs e)
        {
            this.ViewState["keyWordParm"] = this.keyWord.Text.Trim();

            bind(this.ViewState["keyWordParm"].ToString());
        }

        private void bind(string keyWord)
        {
            List<TreatmentInfo> list = null;

            try
            {
                //根据关键字匹配疾病名称
                list = treatmentBll.GetAllTreatmentByName(keyWord);
            }
            catch(Exception ex)
            {
                throw ex;
            }

            this.treatmentList.DataSource = list;
            this.treatmentList.DataBind();
        }

        protected void DeleteBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int[] idList = new int[this.treatmentList.Rows.Count];

                for (int rowIndex = 0; rowIndex < this.treatmentList.Rows.Count; rowIndex++)
                {
                    bool ischeck = ((CheckBox)this.treatmentList.Rows[rowIndex].Cells[0].FindControl("chk")).Checked;
                    if (ischeck)
                    {
                        idList[rowIndex] = Convert.ToInt32(this.treatmentList.DataKeys[rowIndex].Value);
                    }
                }

                treatmentBll.DeleteTreatment(idList);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            bind(this.ViewState["keyWordParm"].ToString());
        }

        protected void pageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.treatmentList.PageIndex = e.NewPageIndex;
            bind(this.ViewState["keyWordParm"].ToString());
        }
    }
}
